﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>主页</title>
    <link href="/js/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
    <div class="container">
        <div id="header" class="row"></div>
        <div class="row">
            <div class="col-3">
                <select class="form-control" id="cult">
                    <option value="zh" selected>中文</option>
                    <option value="ja">日文</option>
                </select>
            </div>
            <div class="col-6">
                <h2 style="height: 80px;" id="title"></h2>
            </div>
        </div>
        <div class="row">
            <div class="col-3">
            </div>
            <div class="col-4" id="message">
            </div>
            <div class="col-5" style="text-align:right;">
                <input type="button" id="getcookie" name="getcookie" value="获取本地化Cookie" class="btn btn-info" />
            </div>
        </div>
        #body
    </div>
    <script src="/js/jquery-3.3.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/jquery.cookie.js"></script>
    <script src="/js/axios/dist/axios.js"></script>
    <script>
        var localizers = null;      
        $(function () {

            if ($.cookie('username') == null) {
                this.location.href = "/login";
            }
            else {          
                axios.get('/localizer', { params: { culture: $.cookie('.AspNetCore.Culture').split("|")[0].split("=")[1] } })
                    .then(function (response) {
                        if (response.status == 200) {
                            localizers = response.data;                     
                            $("#title").html(localizers.username + $.cookie('username'))
                            if ($.cookie('.AspNetCore.Culture') != '') {
                                var culture = $.cookie('.AspNetCore.Culture').split("|")[0].split("=")[1];
                                $("#cult").val(culture)
                                $("#cult").change(function () {
                                    $.cookie('.AspNetCore.Culture', 'c=' + $("#cult").val() + '|uic=' + $("#cult").val());
                                    location.href = location.href
                                });
                            }
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            }
            $('#getcookie').click(function () {
                alert($.cookie('.AspNetCore.Culture'));
            });
        });
    </script>
</body>
</html>